package cn.amoqi.springboot.rabbit.controller;

import cn.amoqi.springboot.rabbit.rabbit.hello.Hello2Sender;
import cn.amoqi.springboot.rabbit.rabbit.hello.Hello2Sender2;
import cn.amoqi.springboot.rabbit.rabbit.hello.HelloSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    private HelloSender helloSender;
    @Autowired
    private Hello2Sender hello2Sender;
    @Autowired
    private Hello2Sender2 hello2Sender2;

    /**
     * 一对一发送
     */
    @RequestMapping("/hello1")
    public void hello1() {
        helloSender.send();
    }

    /**
     * 一个发送多个监听，会发现一个监听到了，这个消息就会被消费了，不会被另一个消费
     * 会均匀的接收到消息
     */
    @RequestMapping("/hello2")
    public void hello2() {
        for (int i = 0; i < 100; i++) {
            hello2Sender.sender("发送者1|" + i);
        }
    }

    /**
     * 多对多发送，多个发送者多个接收者，均匀接收消息
     *
     * @throws Exception
     */
    @RequestMapping("/hello3")
    public void hello3() {
        for (int i = 0; i < 100; i++) {
            hello2Sender.sender("发送者1|" + i);
            hello2Sender2.sender("发送者2|" + i);
        }
    }

}
